package com.beidouapp.service.impl;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beidouapp.dao.AuditLogManager;
import com.beidouapp.domain.pojo.AuditLog;
import com.beidouapp.message.AuditLogMessageUtils;
import com.beidouapp.service.AuditLogService;

@Service
public class AuditLogServiceImpl implements AuditLogService
{
	@Autowired
	private AuditLogManager auditLogManager;

	@Override
	public int countByExample(Map<String, Object> params)
	{
		return auditLogManager.countByExample(params);
	}

	@Override
	public int insert(AuditLog record)
	{
		return auditLogManager.insert(record);
	}

	@Override
	public int insertSelective(AuditLog record)
	{
		return auditLogManager.insertSelective(record);
	}

	@Override
	public List<AuditLog> selectByExample(Map<String, Object> params, int offset, int limit)
	{
		List<AuditLog> logs = auditLogManager.selectByExample(params, offset, limit);
		AuditLogMessageUtils instance = AuditLogMessageUtils.getInstance();
		String key = null;
		for (AuditLog auditLog : logs)
		{
			if(auditLog.getResultStatus() == 1){
				key = auditLog.getAction() + ".success";
			}
			else{
				key = auditLog.getAction() + ".error";
			}
			auditLog.setMessageTemplate(instance.getMessage(key, auditLog.getMessageTemplate()));
		}
		return logs;
	}

	@Override
	public AuditLog selectByPrimaryKey(Long id)
	{
		return auditLogManager.selectByPrimaryKey(id);
	}

}
